package org.shopping.web.commodity;

import org.shopping.domain.Commodity;
import org.shopping.service.commodity.impl.CommodityServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "FindOneCommodityController", value = "/FindOneCommodityController")
public class FindOneCommodityController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 处理response中文乱码问题
        response.setContentType("text/html;charset=utf-8");
        // 获取修改的商品id
        String cidForm = request.getParameter("cid");
        // 执行service层方法
        CommodityServiceImpl commodityService = new CommodityServiceImpl();
        Commodity oneCommodity = commodityService.findOneCommodity(cidForm);

        String str =
                "<form action=\"UpdateCommodityController\" method=\"post\">\n" +
                        "        <input type=\"hidden\" name=\"cid\" value=\""+oneCommodity.getCid()+"\" />\n" +
                        "        <br/>\n" +
                        "        商品名称 <input type=\"text\" name=\"cname\" value=\""+oneCommodity.getCname()+"\" />\n" +
                        "        <br/>\n" +
                        "        商品价格 <input type=\"text\" name=\"cprice\" value=\""+oneCommodity.getCprice()+"\" />\n" +
                        "        <br/>\n" +
                        "        店铺名称 <input type=\"text\" name=\"cshop\" value=\""+oneCommodity.getCshop()+"\" />\n" +
                        "        <br/>\n" +
                        "        商品图片 <input type=\"text\" name=\"cimg\" value=\""+oneCommodity.getCimg()+"\" />\n" +
                        "        <br/>\n" +
                        "        <input type=\"hidden\" name=\"csales\" value=\""+oneCommodity.getCsales()+"\" />\n" +
                        "        <br/>\n" +
                        "        <input type=\"submit\" value=\"确认修改\"/>\n" +
                        "    </form>";
        response.getWriter().write(str);
    }
}
